package com.keepsport.keepsportapi.controller;

import com.keepsport.keepsportapi.config.SystemConfig;
import com.keepsport.keepsportapi.entity.MallCart;
import com.keepsport.keepsportapi.service.intf.MallCartService;
import com.keepsport.keepsportapi.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * __▁▂▃▁__ ﹀ 　　 落霞与孤骛齐飞
 * 　　﹀ _▁▂▃__ 　　 秋水共长天一色
 * 　　__▁▂▁___ ﹀ ﹋ ●
 * 　　﹋ ﹀
 * 　　█▆▅▇▆▅▄▃▄▅▆▄▅▄▃▂▃▄▆▅▇▆▄▅█
 * 　　-__~~--___-▔~~__--__~~~_----__----~~~-
 *
 * @author 1212
 * @create 2022-07-02 20:13
 */
@RestController
@CrossOrigin
@RequestMapping("/api/mallcart/")
@Api(tags = "购物车相关")
public class MallCartController {
    @Resource
    private MallCartService service;
    //查询用户购物车
    @GetMapping("all.do")
    @ApiOperation("查询用户购物车")
    public R selectUser(HttpServletRequest request) {
        //System.out.println(request.getIntHeader(":"+SystemConfig.TOKEN_HEADER));
        return service.userAll(request.getIntHeader(SystemConfig.TOKEN_HEADER));
    }
    //添加购物车
    @PostMapping("add.do")
    @ApiOperation("用户添加购物车")
    public R add(@RequestBody MallCart cart,HttpServletRequest request) {
        return service.add(request.getIntHeader(SystemConfig.TOKEN_HEADER),cart);
    }
    //增加购物车
    @PostMapping("addOne.do")
    @ApiOperation("用户增加商品")
    public R addOne(@RequestBody MallCart cart,HttpServletRequest request) {
        return service.userAdd(request.getIntHeader(SystemConfig.TOKEN_HEADER),cart);
    }
    //坚守购物车
    @GetMapping("del.do")
    @ApiOperation("用户减少购物车")
    public R del(int sid,HttpServletRequest request) {
        return service.userDel(request.getIntHeader(SystemConfig.TOKEN_HEADER),sid);
    }
}
